//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateTag {
        private readonly ITagRepository _tagRepository;

        public CreateTag(ITagRepository tagRepository) {
            _tagRepository = tagRepository;
        }

        public void Execute(Guid userId, ICreateTagCommand tagForm) {
            if (tagForm == null)
                throw new ArgumentNullException("tagForm");

            try {
                var tag = tagForm.ConvertToEntity();
                _tagRepository.Create(tag);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
